import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

// 全局配置
import storage from "./utils/storage"
import http from './config/http.js'

import './assets/scss/reset.scss'
import './assets/scss/common.scss'

// 第三方
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

Vue.prototype.$storage = storage
Vue.prototype.$http = http

Vue.use(ElementUI)

Vue.config.productionTip = false

router.beforeEach((to, from, next) => {

    let adminInfoMe = storage.getLocal('adminInfoMe', true),
        routerwhiteMenu = ['/login']

    store.commit('clickMenuMutations', to.name)

    if(adminInfoMe) {
        if (to.path === '/login') {
            next({ path: '/' })
        } else {
            next()
        }
    } else if (routerwhiteMenu.includes(to.path)) {
        next()
    } else {
        next('/login')
    }
})

new Vue({
    router,
    store,
    render: h => h(App),
    created() {
        store.commit('menuListMutations');
    }
}).$mount('#app')
